import { Provider } from 'mobx-react';
import React from 'react';
import { findDOMNode } from 'react-dom';
import { asyncComponent } from 'react-async-component';
import { render } from 'react-dom';
import ReactDOM from 'react-dom';
import { HashRouter as Router, Redirect, Route, Switch } from 'react-router-dom';
import { Tools, Toast, Progress } from 'weaver-mobile';
import allStore from './stores';
import './style';

window.React = React;
window.getLabel = Tools.getLabel;
window.callApi = Tools.callApi;
window.ecMessage = Toast;
window.findDOMNode = findDOMNode;
window.Progress = Progress;

const coms = {
  AppList: asyncComponent({
    resolve: () => import("./components/app/list"),
  }),
  AppAnalysis: asyncComponent({
    resolve: () => import("./components/app/analysis"),
  }),
  ExcelTaskView: asyncComponent({
    resolve: () => import("./components/app/taskview"),
  }),
  ExcelView: asyncComponent({
    resolve: () => import("./components/app/excel/view/excel-view"),
  }),
  FormHomepage: asyncComponent({
    resolve: () => import("./components/form/home")
  }),
  FormDetail: asyncComponent({
    resolve: () => import("./components/form/detail")
  }),
  FormPermission: asyncComponent({
    resolve: () => import("./components/form/permission")
  }),
  FormShare: asyncComponent({
    resolve: () => import("./common/share/components")
  }),
  FormStatistics: asyncComponent({
    resolve: () => import("./components/form/statistics")
  }),
  FormUnSubmitPersonList: asyncComponent({
    resolve: () => import("./components/form/statistics/UnSubmitPersonList")
  }),
  ExamineForm: asyncComponent({
    resolve: () => import("./components/examine")
  }),
  BrowserHrm: asyncComponent({
    resolve: () => import("./common/browser-hrm")
  }),
  FormSetGroupNoWrite: asyncComponent({
    resolve: () => import("./components/form/permission/setGroupNoWrite")
  }),
  FormPower: asyncComponent({
    resolve: () => import("./components/form/power")
  }),
  FormHrmCondition: asyncComponent({
    resolve: () => import("./components/form/power/HrmCondition")
  }),
  FormWrite: asyncComponent({
    resolve: () => import("./components/form/write")
  }),
  FormFilledWrite: asyncComponent({
    resolve: () => import("./components/form/write/TabCont")
  }),
  FormRemindPerson: asyncComponent({
    resolve: () => import("./components/form/statistics/RemindPerson")
  }),
  FormRemindPersonList: asyncComponent({
    resolve: () => import("./components/form/statistics/RemindPersonList")
  })
}

const Root = () => (
  <Provider {...allStore}>
    <Router>
      <Route
        name="home"
        path="/"
        render={props => (
          <Switch>
            <Route name="appList" path="/app/list" component={coms.AppList} />
            <Route name="appAnalysis" path="/app/analysis/:id" component={coms.AppAnalysis} />
            <Route name="excelTaskView" path="/app/excelTaskView" component={coms.ExcelTaskView} />
            <Route name="excelView" path="/app/excelView" component={coms.ExcelView} />
            <Route name="formHomepage" exact  path="/form" component={coms.FormHomepage} />
            <Route name="formDetailpage" path="/form/detail/:id" component={coms.FormDetail} />
            <Route name="formSetGroupNoWrite" path="/form/permission/setgroupnowrite" component={coms.FormSetGroupNoWrite} /> 
            <Route name="formPermissionpage" path="/form/permission/:id" component={coms.FormPermission} />
            <Route name="formShare" path="/form/share" component={coms.FormShare} />
            <Route name="formUnSubmitPersonList" path="/form/statistics/unsubmit/:id" component={coms.FormUnSubmitPersonList} />
            <Route name="formStatisticspage" path="/form/statistics/:id" component={coms.FormStatistics} />
            <Route name='examine' path='/examine' component={coms.ExamineForm} />
            <Route name='browserHrm' path='/browserHrm' component={coms.BrowserHrm} />
            <Route name='hrmcondition' path='/form/power/hrmcondition' component={coms.FormHrmCondition} />
            <Route name='power' path='/form/power/:id' component={coms.FormPower} />
            <Route name='filled' path='/form/write/:key' component={coms.FormFilledWrite} />
            <Route name='write' path='/form/write' component={coms.FormWrite} />
            <Route name='remindpersonlist' path='/form/remind/list' component={coms.FormRemindPersonList} /> 
            <Route name='remind' path='/form/remind/:id' component={coms.FormRemindPerson} />
            <Redirect to="/form" />
          </Switch>
        )}
      />
    </Router>
  </Provider>
);

Tools.getLocaleLabel("edc", () => { // 多语言
  ReactDOM.render(<Root />, document.getElementById('root'));
});
